<template>
  <div class="pagination-page">
    <el-pagination
      style="margin-top: 20px"
      background
      @size-change="changeSize"
      @current-change="changePage"
      :current-page="page"
      :page-size="per_page"
      :page-sizes="[10, 15, 20, 25, 30]"
      layout="total, prev, pager, next, sizes, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'Pagination',
  props: ['totals'],
  data () {
    return {
      page: 1,
      per_page: 10,
      total: 0
    }
  },
  // 侦听 父组件传递过来的 totals 数据
  watch: {
    totals (newTotal, oldTotal) {
      this.total = newTotal
    }
  },
  methods: {
    // 分页跳转
    changePage (curPage) {
      this.page = curPage
      this.$emit('pagingChange', curPage)
    },
    // 每页显示条数
    changeSize (curSize) {
      this.page = 1
      this.per_page = curSize
      this.$emit('sizeChange', curSize)
    }
  }
}
</script>

<style lang="less" scoped>

</style>
